<?php include "../public/header.php"?>
<body class="dialogPage">
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">选择引用通用任务</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>

    <div class="layui-fluid">
        <div class="layui-row">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body search-div">
                        <div class="layui-form layui-col-space5 search_fors">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" id="keyword" placeholder="任务名称" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block opt-btn-group">
                                <button class="layui-btn layui-btn-sm btn-light" id="search"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="location.reload()" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-card-body">
                        <table id="datalist" lay-filter="datalist"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var parent_page = getQueryVariable('page');

    function show_template(template_type) {
        openPage('../bid_task_template/'+template_type+'.php');
    }

    var level = []; var stage = []; var template = [];
    layui.use(['table','element','facade'],function() {
        var table = layui.table;
        var facade = layui.facade;

        table.render({
            elem: '#datalist'
            ,toolbar: false
            ,defaultToolbar: false
            ,method:'post'
            ,url: facade.url(ask_bid_task_general_list)
            ,page: true
            ,request: {pageName: 'page',limitName: 'pagesize'}
            ,parseData: function(res){
                level = res.data.level;
                stage = res.data.stage;
                template = res.data.template;

                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            ,response: {statusCode: 2000}
            ,cols: [[
                {type:'checkbox',fixed:'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field:'stage_name',title:'任务阶段'}
                ,{field:'template_name',title:'任务模板',templet:function (e) {
                    return '<span style="cursor: pointer;color: #65b5ff" onclick="show_template(\''+e.template_type+'\')">'+e.template_name+'</span>';
                }}
                ,{field:'name',title:'任务名称'}
                ,{field:'level',title:'优先级'}
                ,{field:'liable_name',title:'责任人'}
                ,{field:'describe',title:'任务描述'}
            ]]
        });

        // 查询数据-以前的查询条件都会保留
        $('#search').on('click', function(){
            var keyword = $('#keyword').val();
            table.reload('datalist', {
                page:{curr:1},
                where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                    keyword:keyword
                }
            });
        });

        $('#submit').on('click', function () {
            var checkStatus = layui.table.checkStatus('datalist');
            var data = checkStatus.data;
            if(data.length === 0){
                facade.error('请选择数据'); return false;
            }
            if(parent_page === 'bid'){
                var str = '';
                var length = $('.short_table_tbody tr', parent.document).length;
                for(var i=0;i<data.length;i++){
                    str += '<tr>';
                    str += '<td style="width: 45px">'+(length+1+i)+'</td>';
                    str += '<td><select class="layui-select stage">';
                    str += '<option value=""></option>';
                    for(var j in stage){
                        if(data[i].stage == j){
                            str += '<option value="'+j+'" selected>'+stage[j]+'</option>';
                        }else{
                            str += '<option value="'+j+'">'+stage[j]+'</option>';
                        }
                    }
                    str += '</select></td>';
                    str += '<td><input type="text" class="layui-input name" value="'+data[i].name+'"></td>';
                    str += '<td><select class="layui-select templateid">';
                    str += '<option value=""></option>';
                    for(var j=0;j<template.length;j++){
                        if(data[i].templateid == template[j].id){
                            str += '<option value="'+template[j].id+'" selected>'+template[j].name+'</option>';
                        }else{
                            str += '<option value="'+template[j].id+'">'+template[j].name+'</option>';
                        }
                    }
                    str += '</select></td>';
                    str += '<td><select class="layui-select level">';
                    str += '<option value=""></option>';
                    for(var j in level){
                        if(data[i].level == level[j]){
                            str += '<option value="'+level[j]+'" selected>'+level[j]+'</option>';
                        }else{
                            str += '<option value="'+level[j]+'">'+level[j]+'</option>';
                        }
                    }
                    str += '</select></td>';
                    str += '<td><input type="text" class="layui-input liableid" value="'+data[i].liable_name+'" key="'+data[i].liableid+'" readonly onclick="choose_user(this)"></td>';
                    str += '<td><input type="text" class="layui-input claim_dt bdate_ymd" readonly></td>';
                    str += '<td><input type="text" class="layui-input describe" value="'+data[i].describe+'"></td>';
                    str += '</tr>';
                }
                $('.short_table_tbody', parent.document).append(str);

                parent.render_date();
                parent.render_from();

                // 判断明细中是否有选中的行或列
                reload_table_list_bac('short_table_tbody', 1);
            }

            if(parent_page === 'bid_task'){
                var str = '';
                var length = $('.short_table_tbody tr', parent.document).length;
                for(var i=0;i<data.length;i++){
                    str += '<tr>';
                    str += '<td style="width: 45px">'+(length+1+i)+'</td>';
                    str += '<td><select class="layui-select stage">';
                    str += '<option value=""></option>';
                    for(var j in stage){
                        if(data[i].stage == j){
                            str += '<option value="'+j+'" selected>'+stage[j]+'</option>';
                        }else{
                            str += '<option value="'+j+'">'+stage[j]+'</option>';
                        }
                    }
                    str += '</select></td>';
                    str += '<td><input type="text" class="layui-input name" value="'+data[i].name+'"></td>';
                    str += '<td><select class="layui-select templateid">';
                    str += '<option value=""></option>';
                    for(var j=0;j<template.length;j++){
                        if(data[i].templateid == template[j].id){
                            str += '<option value="'+template[j].id+'" selected>'+template[j].name+'</option>';
                        }else{
                            str += '<option value="'+template[j].id+'">'+template[j].name+'</option>';
                        }
                    }
                    str += '</select></td>';
                    str += '<td><select class="layui-select level">';
                    str += '<option value=""></option>';
                    for(var j in level){
                        if(data[i].level == level[j]){
                            str += '<option value="'+level[j]+'" selected>'+level[j]+'</option>';
                        }else{
                            str += '<option value="'+level[j]+'">'+level[j]+'</option>';
                        }
                    }
                    str += '</select></td>';
                    str += '<td><input type="text" class="layui-input liableid" value="'+data[i].liable_name+'" key="'+data[i].liableid+'" readonly onclick="choose_user(this)"></td>';
                    str += '<td><input type="text" class="layui-input describe" value="'+data[i].describe+'"></td>';
                    str += '</tr>';
                }
                $('.short_table_tbody', parent.document).append(str);

                parent.render_date();
                parent.render_from();

                // 判断明细中是否有选中的行或列
                reload_table_list_bac('short_table_tbody', 1);
            }
            layer_close();
        });

        // 清空
        $('#empty').on('click', function () {
            layer_close();
        });
    });
</script>
</body>
</html>
